/* GUI CONVERTED from ecmt04.p (converter v1.76) Tue Dec 31 10:45:19 2002 */
/* ecmt04.p - PCO MAINTENANCE Text Maintenance                                */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.11.1.5 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.4      LAST MODIFIED: 07/01/93   BY: pma *H013*                */
/* REVISION: 7.4      LAST MODIFIED: 10/19/96   BY: *H0N6*  Russ Witt         */
/* REVISION: 8.6      LAST MODIFIED: 12/09/96   BY: Joe Gawel *K00C*          */
/* REVISION: 8.6      LAST MODIFIED: 01/08/97   BY: *H0QR* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 05/28/97   BY: *H0Z7* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 07/02/97   BY: *J1PM* Amy Esau           */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 08/04/98   BY: *J2T6* Sandesh Mahagaokar */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.11.1.5 $    BY: Katie Hilbert         DATE: 12/27/02  ECO: *P0L8*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

{ecmtparm.i}

define new shared variable cmtindx like cmt_indx.
define shared variable frameb_title as character format "x(40)".
define variable ecd3ref     like cmt_ref.
define variable cdtype      like cd_type.
define variable del-yn      like mfc_logical initial no.
define variable ecmid       like wo_lot.
define variable dbase       like si_db.
define variable i           as integer.
define variable cmt_recno   as recid.
define variable first-time  like mfc_logical initial yes.
define variable error-count as integer no-undo.
define variable seq         like cmt_seq.
define variable ecd3order   like ecd3_order no-undo initial 1.
define buffer ecd3 for ecd3_det.

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
ecm_nbr             colon 12 label "Number"
   ecmid               colon 36
   dbase               colon 58
   cmt_type            colon 74 label "Type"
   ecd3ref             colon 12
   ecd3order           colon 60 format ">>9"
   cmt_seq             colon 72
   skip(1)
   cmt_cmmt            at 2     no-label
 SKIP(.4)  /*GUI*/
with frame form03 attr-space side-labels
    width 80 overlay NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-form03-title AS CHARACTER.
 F-form03-title = frameb_title.
 RECT-FRAME-LABEL:SCREEN-VALUE in frame form03 = F-form03-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame form03 =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame form03 + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame form03 =
  FRAME form03:HEIGHT-PIXELS - RECT-FRAME:Y in frame form03 - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME form03 = FRAME form03:WIDTH-CHARS - .5. /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame form03:handle).

find ecm_mstr where recid(ecm_mstr) = ecm_recid
exclusive-lock no-error no-wait.
if locked(ecm_mstr) then do:
   msgnbr = 7422.
   warnlvl = 4.
   return.
end.
if not available (ecm_mstr) then do:
   msgnbr = 5630.
   warnlvl = 2.
   return.
end.

cdtype = "".

find first pcc_ctrl no-lock no-error.
if available pcc_ctrl then cdtype = pcc_cmmt_type.

mainloop:
repeat with frame form03:
/*GUI*/ if global-beam-me-up then undo, leave.

   pause 0.
   clear frame form03 all no-pause.
   clear frame form03.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame form03 = F-form03-title.
   display
      substring(ecm_nbr,1,8)  @ ecm_nbr
      substring(ecm_nbr,9,8)  @ ecmid
      substring(ecm_nbr,17,8) @ dbase
   with frame form03.
   do i = 1 to 15:
      display "" @ cmt_cmmt[i].
   end.

   prompt-for cmt_type with frame form03.
   assign cdtype = input cmt_type.

   prompt-for ecd3ref with frame form03
   editing:
      {mfnp01.i ecd3_det ecd3ref ecd3__qad03 ecd3_nbr ecm_nbr ecd3_cmt}
      if recno <> ? then do:
         display
            ecd3__qad03 @ ecd3ref
            ecd3_order  @ ecd3order
         with frame form03.
         ecd3order = ecd3_order.

         find first cmt_det where cmt_indx = ecd3_cmtindx
         no-lock no-error.
         if available cmt_det then
            display
               cmt_seq + 1 @ cmt_seq
               cmt_cmmt
            with frame form03.
      end.
   end.
   if input ecd3ref = "" then do:
      {pxmsg.i &MSGNUM=40 &ERRORLEVEL=1}
      pause.
      undo, retry.
   end.

   update ecd3order.

   find first ecd3_det
      where ecd3_nbr = ecm_nbr and
            ecd3_order = ecd3order and
            ecd3__qad03 = input ecd3ref
   exclusive-lock no-error.

   if not available ecd3_det then do:
      do i = 1 to 15:
         display "" @ cmt_cmmt[i].
      end.

      create ecd3_det.
      assign
         ecd3_nbr     = ecm_nbr
         ecd3__qad03  = input ecd3ref
         ecd3_order   = 0
         ecd3_cmtindx = 0.

      for each ecd3 no-lock where ecd3.ecd3_nbr = ecm_nbr:
         if ecd3.ecd3_order >= ecd3_det.ecd3_order
         then
            ecd3_det.ecd3_order = ecd3.ecd3_order + 1.
      end.
   end.

   find first cmt_det where cmt_indx = ecd3_cmtindx no-lock no-error.
   if available cmt_det then display cmt_seq + 1 @ cmt_seq cmt_cmmt.
   else display 1 @ cmt_seq.

   cmtindx = ecd3_cmtindx.

   do with frame form03:
      if cmtindx <> 0 then
         find first cmt_det where cmt_indx = cmtindx no-lock no-error.
      if available cmt_det then do:
         cmt_recno = recid(cmt_det).
         display cmt_seq + 1 @ cmt_seq cmt_cmmt.
      end.
      else do:
         display 1 @ cmt_seq.
         find first cd_det no-lock where cd_ref = ecd3__qad03
            and cd_type = cdtype and cd_lang = global_user_lang no-error.
         if available cd_det then do:
            do i = 1 to 15:
               display cd_cmmt[i] @ cmt_cmmt[i].
            end.
         end.
      end.
   end.

   repeat with frame form03:
/*GUI*/ if global-beam-me-up then undo, leave.


      if keyfunction(lastkey) = "end-error" or
         keyfunction(lastkey) = "endkey" or
         lastkey = keycode("F4")
      then leave.

      if can-find (first cmt_det where cmt_indx = cmtindx)
         or first-time = no then do:

         prompt-for cmt_seq
         editing:
            {mfnp05.i cmt_det cmt_ref "cmt_indx = cmtindx" cmt_seq
               "(input cmt_seq - 1)"}
            if recno <> ? then
               display cmt_seq + 1 @ cmt_seq cmt_cmmt.
         end.

         /* ADD/MOD/DELETE */
         find cmt_det where cmt_indx = cmtindx
            and cmt_seq = input cmt_seq - 1 exclusive-lock no-error.
         if available cmt_det then do:
            display cmt_seq + 1 @ cmt_seq cmt_cmmt.
            cmt_recno = recid(cmt_det).
         end.
      end.

      if not available cmt_det then do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         create cmt_det.

         display cmt_cmmt.
         seq = input cmt_seq - 1.

         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

         if can-find (first cd_det where cd_ref = ecd3__qad03
            and cd_type = cdtype and cd_lang = global_user_lang
            and cd_seq = seq)
         then do:
            find first cd_det no-lock
               where cd_ref = ecd3__qad03
                 and cd_type = cdtype
                 and cd_lang = global_user_lang
               no-error.

            if available cd_det then do:
               do i = 1 to 15:
                  display cd_cmmt[i] @ cmt_cmmt[i].
               end.
            end.
         end.
         else
            display cmt_cmmt.

         assign
            cmt_print = ""
            cmt_ref   = ecd3__qad03
            cmt_type  = cdtype
            cmt_lang  = global_user_lang.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      ststatus = stline[2].
      status input ststatus.
      del-yn = no.
      first-time = no.

      set1:
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         set text(cmt_cmmt) go-on ("F5" "CTRL-D").

         /* DELETE */
         if lastkey = keycode("F5")
            or lastkey = keycode("CTRL-D")
         then do:
            del-yn = yes.
            {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
            if not del-yn then undo set1, retry.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if del-yn then do:
         delete cmt_det.

         del-yn = no.

         /* TO ALLOW MULTIPLE PAGES COMMENTS TO BE DELETED */

         find next cmt_det exclusive-lock where cmt_indx = cmtindx
            no-error.
         if not available cmt_det then
            find prev cmt_det exclusive-lock where cmt_indx = cmtindx
            no-error.

         if available cmt_det then do:
            display
               cmt_seq + 1 @ cmt_seq
               cmt_ref @ ecd3ref
               cmt_cmmt.
            cmt_recno = recid(cmt_det).
         end.

         if not available cmt_det then do:
            cmtindx = 0.
            delete ecd3_det.
            next mainloop.
         end.
      end.

      if cmtindx = 0 then do:
         error-count = 0.
         assign cmt_det.cmt_seq = input cmt_det.cmt_seq - 1.
         {mfrnseq.i cmt_det cmt_det.cmt_indx cmt_sq01}
         assign
            cmtindx      = cmt_det.cmt_indx
            ecd3_cmtindx = cmt_det.cmt_indx
            recno        = recid(cmt_det)
            cmt_recno    = recid(cmt_det).

      end.
      else do:

         assign
            cmt_indx  = cmtindx
            cmt_seq   = input cmt_seq - 1
            recno     = recid(cmt_det)
            cmt_recno = recid(cmt_det).

      end.

      release cmt_det.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if ecd3_cmtindx = 0 then delete ecd3_det.

end.
/*GUI*/ if global-beam-me-up then undo, leave.

